"""
读取yaml文件
"""
import yaml

def read_yaml(filepath):
    """从指定的YAML文件加载数据"""
    try:
        with open(filepath, 'r', encoding='utf-8') as f:
            data = yaml.safe_load(f)
            # 期望加载的数据是列表，如果不是，可能需要根据实际结构调整
            if not isinstance(data, list):
                print(f"Warning: YAML data in {filepath} is not a list. Returning empty list.")
                return []
            return data
    except FileNotFoundError:  # 文件不存在错误
        print(f"Error: YAML file not found at {filepath}")
        return []
    except yaml.YAMLError as e:  # YAML 解析错误
        print(f"Error loading YAML file {filepath}: {e}")
        return []
    except Exception as e:  # 其他未知错误
        print(f"An unexpected error occurred loading YAML {filepath}: {e}")
        return []


# print(read_yaml('../data/devicemodel_data.yaml'))
